package com.zhdl.modules.process.task;

import cn.hutool.core.util.HexUtil;
import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
import com.zhdl.common.ytools.S7Config;
import com.zhdl.hardware_contact.hardware_config.entity.ProjectConfiguration;
import com.zhdl.hardware_contact.hardware_web.service.HardwareContactService;
import com.zhdl.hardware_contact.hardware_web.service.HardwareCurrentService;
import com.zhdl.hardware_contact.hardware_web.service.ProcessSportService;
import com.zhdl.modules.common.production.service.ProductionService;
import com.zhdl.modules.process.service.ProjectConfigProcessService;
import com.zhdl.network.common_skipfaq.analysis.CommDemoAnalysis;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Random;


@Slf4j
@Component
public class ProcessScheduledTask {

//    @Resource
//    private ProjectConfigProcessService projectConfigProcessService;

    @Resource
    private HardwareCurrentService hardwareCurrentService;

    @Resource
    private ProcessSportService processSportService;

    @Resource
    private HardwareContactService hardwareContactService;

    @Resource
    private ProductionService productionService;

    public String[] plcValueDemo = new String[]{
            "FF0000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "0000000000000FFFF0" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "FFFF00000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "FF0000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000080"
                    + "0000007C0000007C00" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000",
            "00FF00000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "0000007A0000007A00" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000",

            "FFFF00000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "0000007B0000007B00" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000",
            "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000"
                    + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000" + "000000000000000000",

    };

//    @Scheduled(fixedRate = 2000, initialDelay = 2 * 1000)
//    public void task() {
//        Random random = new Random();
//        int i = random.nextInt(4);
//        projectConfigProcessService.readProjectConfigToRAM(plcValueDemo[i]);
//        hardwareCurrentService.updateHardwareCurrent();
//    }

    @Resource
    S7PLC s7PLC;

    ProjectConfiguration projectConfiguration = new ProjectConfiguration("产量","0",2,"22");
    @Scheduled(fixedRate = 500, initialDelay = 1 * 500)
    public void task() {
//    String plcValue = "00000800c11b2788000000003dcccccd00000000000008004310a60a00000000000000000000cccd00000800448e852900000000000000000000000000008041040000000000000000000000";
//    projectConfigProcessService.processBitValue(plcValue,"62");
        hardwareCurrentService.updateHardwareCurrent();

        projectConfiguration.setDbAddress("DB3");
        productionService.updateProduction("DB3.0",24,projectConfiguration);
    }




}
